/***********************************************************************************
**  
* @copyright (c) 2013-2100,  Technology Co., LTD. All Right Reserved.
*
************************************************************************************/
/**
* @file     duye_md5.h
* @version     
* @brief      
* @author
* @date     2014-8-7
* @note 
*
*  1. 2014-8-7 Created this file
* 
*/
#pragma once

#include <string>
#include <duye_type.h>

namespace duye {

/*!
 * Manage MD5.
 */
class MD5
{
public:
    //! construct a MD5
    MD5();

    //! construct a md5src from char *
    MD5(const char * md5src);

    //! construct a MD5 from a 16 bytes md5
    MD5(unsigned long* md5src);

    //! construct a MD5 from any buffer
    void generateMD5(unsigned char* buffer,int bufferlen);

    //! to a string
    std::string toString();

    //! add a other md5
    MD5 operator +(MD5 adder);

    //! just if equal
    bool operator ==(MD5 cmper);

    //! give the value from equer
    // void operator =(MD5 equer);

    unsigned long m_data[4];

private:
    struct md5_context
    {
        uint32 total[2];
        uint32 state[4];
        uint8 buffer[64];
    };

    void md5_starts(struct md5_context *ctx);
    void md5_process(struct md5_context *ctx, uint8 data[64]);
    void md5_update(struct md5_context *ctx, uint8 *input, uint32 length);
    void md5_finish(struct md5_context *ctx, uint8 digest[16]);
};
}
